<template>
	<view class="container">
		<u-cell-group class="class-group" :border="false">
			<u-cell-item :arrow="false">
				<view class="class-list">
					<view class="class-list-item">
						<view class="class-list-item__avatar">
							<image class="avatar" :src="classData.course.image" mode="aspectFill"></image>
							<view class="label">预约</view>
							<view class="number" @click="dropSwitch"><text>{{classData.appointment.length}}</text>/{{classData.course.people_count}} <u-icon class="arrow" :name="classData.isSelected?'arrow-down':'arrow-up'" color="#D7D7D7" size="18"></u-icon></view>
						</view>
						<view class="class-list-item__content">
							<view class="title">{{classData.course.name}}</view>
							<view class="star">难易度：<u-rate :current="classData.course.degree" :disabled="true" inactive-icon="star-fill" inactive-color="#DFDFDF" active-color="#F5C822" size="24" gutter="6"></u-rate></view>
							<view class="info">教练：{{classData.teacher.name}}</view>
							<view class="info">教室：{{classData.classroom.name}}</view>
							<view class="info">时间：{{classData.start_time}}-{{classData.end_time}}</view>
						</view>
						<button open-type="share" class="share-box">
							<image class=" share" src="../../../static/icons/icon_share.png" mode="aspectFit" ></image>
						</button>
					</view>
					<view class="class-list-user" v-if="classData.appointment.length>0 && classData.isSelected">
						<view class="title">已预约上课的学员</view>
						<view class="thumb-box">
							<image class="thumb" v-for="(img,idx) in classData.appointment" :key="idx" :src="img.avatar" mode="aspectFill"></image>
						</view>
					</view>
				</view>
			</u-cell-item>
			<u-cell-item :arrow="false">
				<view class="class-list">
					<view class="class-group__title">课程详情</view>
					<view class="class-group__text">
						<u-parse :html="classData.course.description"></u-parse>
					</view>
				</view>
			</u-cell-item>
		</u-cell-group>
		<view class="class-discuss">
			<view class="class-discuss__title">课程评价（{{total}}）</view>
			<view class="class-discuss__list">
				<view class="class-discuss__item" v-for="(item,index) in commentList">
					<view class="item-head">
						<image class="avatar" :src="item.user.avatar" mode="aspectFill">
						</image>
						<view class="content">
							<view class="name">{{item.nickname}}</view>
							<view class="time">{{item.createtime}}</view>
						</view>
						<u-rate :current="item.star" :disabled="true" inactive-icon="star-fill" inactive-color="#DFDFDF" active-color="#F5C822" size="24" gutter="6"></u-rate>
					</view>
					<view class="item-body">{{item.content}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				course_arrangement_id:0,
				classData: {
					appointment:[]
				},
				commentList:[],
				commentMore:{page:1},
				total:0
			}
		},
		onLoad(options) {
			if(options.arrangement_id){
				this.course_arrangement_id = options.arrangement_id;
				this.fetchDetail();
				this.fetch();
			}
		},
		// 页面到达底部触发
		onReachBottom() {
			this.fetch();
		},
		onShareAppMessage() {
			return {
			    title: this.classData.course.name,
			    path: '/pages/class/classDetail/classDetail?course_id=' + this.classData.id,
			    imageUrl: this.classData.course.image || '',
			}
		},
		onShareTimeline() {
			return {
			    title: this.classData.course.name,
			    path: '/pages/class/classDetail/classDetail?course_id=' + this.classData.id,
			    imageUrl: this.classData.course.image || '',
			}
		},
		methods: {
			//获取排课信息
			fetchDetail(){
				this.$core.get({url:'fitness.course_arrangement/detail',data:{course_arrangement_id:this.course_arrangement_id},success:(ret)=>{
					this.classData = ret.data;
				}});
			},
			
			//获取评分列表
			fetch(){
				this.$utils.fetch(this, 'fitness.course_arrangement/arrangement_lists', {course_arrangement_id:this.course_arrangement_id,pagesize:10}, 'commentMore', 'commentList', 'data', data=>{
				  this.total = data.total;
				})
			
			},
			
			dropSwitch() {
				let data = this.classData
				let isSelected = data.isSelected
				this.$set(data,'isSelected',!isSelected)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.class-group {
		display: block;
		margin-bottom: 16rpx;
		background-color: #FFFFFF;
		color: #333333;
		border-radius: 24rpx;
		overflow: hidden;
		
		.class-group__title,
		/deep/ .u-cell_title,
		/deep/ .u-input__textarea {
			font-size: 26rpx;
			color: #333333;
		}
		
		.class-group__text {
			margin-top: 10rpx;
			line-height: 34rpx;
			font-size: 24rpx;
			color: #D7D7D7;
		}
	}
	.class-list {
		padding: 0;
		text-align: left;
	}
	.class-discuss {
		padding: 24rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		overflow: hidden;
		&__title {
			margin-bottom: 10rpx;
			line-height: 38rpx;
			font-size: 26rpx;
			color: #333333;
		}
		&__item {
			border-top: 1rpx #EDEDED solid;
			padding: 24rpx 0;
			
			&:first-child {
				border-top: 0;
			}
			
			.item-head {
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
				font-size: 24rpx;
				color: #999999;
				.avatar {
					display: block;
					width: 54rpx;
					height: 54rpx;
					border-radius: 99px;
				}
				.content {
					flex: 1;
					padding: 0 15rpx;
					line-height: 20rpx;
					font-size: 18rpx;
					color: #999999;
					overflow: hidden;
				}
				.name {
					line-height: 30rpx;
					font-size: 22rpx;
					color: #101010;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
				}
			}
			
			.item-body {
				margin-top: 15rpx;
				line-height: 30rpx;
				font-size: 22rpx;
				color: #666666;
			}
		}
	}
	.share-box {
		position: absolute;
		right: 25rpx;
		top: 220rpx;
		display: block;
		width: 40rpx;
		height: 40rpx;
		padding: 0;
		background: transparent;
		&::after {
			display: none;
		}
	}
	.share {
		display: block;
		width: 40rpx;
		height: 40rpx;
	}
</style>